package com.caiya.controller;

import com.caiya.cart.CartRequest;
import com.caiya.cart.Res;
import com.caiya.cart.entity.CartServiceType;
import com.caiya.cart.vo.servicetype.ServiceTypeAddVo;
import com.caiya.cart.vo.servicetype.ServiceTypeListVo;
import com.caiya.cart.vo.servicetype.ServiceTypeUpdateVo;
import com.caiya.service.CartServiceTypeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2018/12/3 0003.
 */
@RestController
@Api(description = "汽车服务类型")
@RequestMapping("/api/servicetype")
public class CartServiceTypeController {
    @Autowired
    private CartServiceTypeService cartServiceTypeService;

    @PostMapping(value = "/list")
    @ApiOperation(value = "列表",notes = "")
    public Res list(@RequestBody ServiceTypeListVo serviceTypeListVo){
        Res res = null;
        try {
            PageInfo<CartServiceType> info = cartServiceTypeService.list(serviceTypeListVo);
            res = new Res(info);
        }catch (Exception e){
            e.printStackTrace();
            res = new Res(Res.CODE_FAIL,e.getMessage());
        }
        return res;
    }

    @PostMapping(value = "/add")
    @ApiOperation(value = "新增",notes = "")
    public Res add(@RequestBody ServiceTypeAddVo serviceTypeAddVo){
        Res res = null;
        try {
            int i = cartServiceTypeService.add(serviceTypeAddVo);
            res = new Res(i);
        }catch (Exception e){
            e.printStackTrace();
            res = new Res(Res.CODE_FAIL,e.getMessage());
        }
        return res;
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "修改",notes = "d")
    public Res update(@RequestBody ServiceTypeUpdateVo serviceTypeUpdateVo){
        Res res = null;
        try {
            int i = cartServiceTypeService.update(serviceTypeUpdateVo);
            res = new Res(i);
        }catch (Exception e){
            e.printStackTrace();
            res = new Res(Res.CODE_FAIL,e.getMessage());
        }
        return res;
    }
}
